import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: (resolve) => require(['@/views/redirect'], resolve)
      }
    ]
  },
  {
    path: '/login',
    component: (resolve) => require(['@/views/login'], resolve),
    name:'Login',
    meta: { title: '登录' }
  },
  {
    path: '/register/common',
    name:'Common',
    component: (resolve) => require(['@/views/register/Common'], resolve),
    meta: { title: '用户注册' }
  },
  {
    path: '/register/sponsor',
    name:'Sponsor',
    component: (resolve) => require(['@/views/register/Sponsor'], resolve),
    meta: { title: '赞助商用户注册' }
  },
  {
    path: '',
    component: Layout,
    redirect: 'home',
    children: [
      {
        path: 'home',
        component: (resolve) => require(['@/views/home'], resolve),
        name: 'Home',
        meta: { title: '社联首页' }
      }
    ]
  },
  {
    path: '/link',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/links'], resolve),
        name: 'Link',
        meta: { title: '校内链接' }
      }
    ]
  },
  {
    path: '/news',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/news'], resolve),
        name: '校园新闻',
        meta: { title: '校园新闻' },
        // redirect:'list/edit',
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/news/Edit'], resolve),
            name: 'NewsContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/notice',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/notice'], resolve),
        name: '通知公告',
        meta: { title: '通知公告' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/notice/Edit'], resolve),
            name: 'NoticeContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/policy',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/policy'], resolve),
        name: '政策法规',
        meta: { title: '政策法规' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/policy/Edit'], resolve),
            name: 'PolicyContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/activity',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/activity'], resolve),
        name: '社联活动',
        meta: { title: '社联活动' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/activity/Edit'], resolve),
            name: 'ActivityContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/dept',
    component: Layout,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/dept'], resolve),
        name: '社联社团',
        meta: { title: '社联社团' },
        children: [
          {
            path: 'list',
            component: (resolve) => require(['@/views/dept/List'], resolve),
            name: 'DeptContent',
            meta: { title: '正文内容' },
            children:[
              {
                path:'edit',
                component: (resolve) => require(['@/views/dept/Edit'], resolve),
                name:'DeptEdit',
                meta: { title: '正文内容' },
              }
            ]
          }
        ]
      }
    ]
  },
  {
    path: '/post',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/post'], resolve),
        name: '组织机构',
        meta: { title: '组织机构' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/post/Edit'], resolve),
            name: 'PostContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/honour',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/honour'], resolve),
        name: '光荣之星',
        meta: { title: '光荣之星' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/honour/Edit'], resolve),
            name: 'HonourContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/pick',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/pick'], resolve),
        name: '社联风采',
        meta: { title: '社联风采' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/pick/Edit'], resolve),
            name: 'PickContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/elect',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/elect'], resolve),
        name: '换届选举',
        meta: { title: '换届选举' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/elect/edit'], resolve),
            name: 'ElectContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },
  {
    path: '/sponsor',
    component: Layout,
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/sponsor'], resolve),
        name: '企业赞助',
        meta: { title: '企业赞助' },
        children: [
          {
            path: 'edit',
            component: (resolve) => require(['@/views/sponsor/edit'], resolve),
            name: 'SponsorContent',
            meta: { title: '正文内容' }
          }
        ]
      }
    ]
  },



  {
    path: '/message',
    component: (resolve) => require(['@/views/message'], resolve),
    name:'消息',
    meta: { title: '消息' },
    redirect: '/message/comment',
    children: [
      {
        path: 'comment',
        component: (resolve) => require(['@/views/message/comment'], resolve),
        name: '评论',
        meta: { title: '评论'}
      },
      {
        path: 'notify',
        component: (resolve) => require(['@/views/message/notify'], resolve),
        name: '消息通知',
        meta: { title: '消息通知' }
      }
    ]
  },
  {
    path: '/user',
    component: (resolve) => require(['@/views/user'], resolve),
    name:'个人中心',
    meta: { title: '个人中心' },
    redirect: '/user/profile',
    children: [
      {
        path: 'profile',
        component: (resolve) => require(['@/views/user/userInfo'], resolve),
        name: '个人资料',
        meta: { title: '个人资料' }
      },
      {
        path: 'resetPwd',
        component: (resolve) => require(['@/views/user/resetPwd'], resolve),
        name: '修改密码',
        meta: { title: '修改密码'}
      }
    ]
  },
  {
    path: '/personal',
    component: (resolve) => require(['@/views/personal'], resolve),
    name:'个人主页',
    meta: { title: '个人主页' }
  },


  {
    path: '/trends',
    component: (resolve) => require(['@/views/trends'], resolve),
    name:'社联动态',
    meta: { title: '社联动态' },
    redirect: '/trends/list',
    children: [
      {
        path: 'list',
        component: (resolve) => require(['@/views/trends/list'], resolve),
        name: '动态集',
        meta: { title: '动态集' }
      },
      {
        path: 'edit',
        component: (resolve) => require(['@/views/trends/edit'], resolve),
        name: '动态查看',
        meta: { title: '动态查看' }
      }
    ]
  },
  {
    path: '/forum',
    component: (resolve) => require(['@/views/forum'], resolve),
    name:'社联论坛',
    meta: { title: '社联论坛' },
    redirect: '/forum/home',
    children: [
      {
        path: 'home',
        component: (resolve) => require(['@/views/forum/home'], resolve),
        name: '论坛首页',
        meta: { title: '论坛首页' }
      },
      {
        path: 'write',
        component: (resolve) => require(['@/views/forum/write'], resolve),
        name: '我要发贴',
        meta: { title: '我要发贴' }
      },
      {
        path: 'edit',
        component: (resolve) => require(['@/views/forum/edit'], resolve),
        name: '帖子查看',
        meta: { title: '帖子查看' }
      },
    ]
  },

]

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
